package com.google.code.seditor.gui.model;

import java.io.File;

import android.database.Cursor;

import com.google.code.seditor.SeditorActivity;
import com.google.code.seditor.db.DaoFactory;
import com.google.code.seditor.db.FileDao;

public class MainModel {

	private SeditorActivity mainActivity = null;
	
	private Cursor cursor;
	
	public static final String KEY_TITLE="title";

	public MainModel(SeditorActivity activity) {
		this.mainActivity = activity;
	}
	
	public Cursor getAllNote(){
		this.cursor=((FileDao)DaoFactory.getDao(FileDao.class,mainActivity)).fetchAllNotes();
		
		return this.cursor;
	}
		
	public int deleteNote(long id){		
		//delete file
		FileDao dao=(FileDao)DaoFactory.getDao(FileDao.class,mainActivity);
		Cursor fileCursor=dao.fetchNote(id);
		String path=fileCursor.getString(FileDao.INDEX_PATH);
		File noteFile=new File(path);
		noteFile.delete();	
		
		//delete DB record
		((FileDao)DaoFactory.getDao(FileDao.class,mainActivity)).deleteNote(id);
		
		//normal return
		return 0;
		
	}

	public Cursor getCursor() {
		return cursor;
	}
		
}
